package com.escape.wx.handler;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: escape_zebra
 * @CreateTime: 2025-01-16  20:43
 * @Description: TODO
 * @Version: 1.0
 */
@Component
public class WxChatMsgFactory {

    @Resource
    private List<WxChatMsgHandler> wxChatMsgHandlerList;

    private Map<WxChatMsgTypeEnum,WxChatMsgHandler> handlerMap = new HashMap<>();

    public WxChatMsgHandler getWxChatMsgHandler(String msgType){
        WxChatMsgTypeEnum typeEnum = WxChatMsgTypeEnum.getEnum(msgType);
        return this.handlerMap.get(typeEnum);
    }

    @PostConstruct
    public void init(){
        for (WxChatMsgHandler handler : wxChatMsgHandlerList) {
            this.handlerMap.put(handler.getMsgType(), handler);
        }
    }


}
